// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

// 云函数入口函数
const db = cloud.database()
const _ = db.command
exports.main = async (event, context) => {
    let foods = event.foods
    foods.forEach(food => {
    return db.collection('food').doc(food._id)
    .update({
      data: {
        sell: _.inc(food.num)
      }
    })
  });
}